<%@ page import="com.apexedu.identity.entity.TSysUser" %>
<%@ page import="com.apexedu.identity.IdConstants" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    request.setAttribute("basePath", request.getContextPath());
    TSysUser user = (TSysUser) request.getSession().getAttribute(IdConstants.SESSION_USER);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>青海警官职业学院</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="${basePath}/resources/css/yx.qh.css" rel="stylesheet">
    <script type="text/javascript" src="${basePath}/resources/ui/js/jquery-1.10.2.min.js"></script>
    <script src="${basePath}/resources/js/common/json2.js"></script>
    <script src="${basePath}/resources/js/common/myutil.js"></script>
    <script type="text/javascript" src="${basePath}/component/layer1.9.3/layer.js"></script>
    <script>
        var jfnameArray = new Array();
        $(function () {
            var jfname = '${jfname}';
            $.each(jfname.split(","), function (i, item) {
                jfnameArray.push(item);
            });

            $("#titleDiv :text").blur(function () {
                doSearch($(this).attr("id"));
            });
            $(".greenchannel").click(function () {
                if ($(this).is(".notallow")) {
                    layer.alert("已缴费！");
                    return false;
                }
                doGreenchannel();
            });
            $(".submit").click(function () {
                if ($(this).is(".notallow")) {
                    layer.alert("已缴费！");
                    return false;
                }
                doSubmit();
            })
            doChangeJfqk('${jfqk}');

            $("#sfxm").on("blur", ":text", function () {
                var $tr = $(this).parents("tr:first");
                var $table = $(this).parents("table:first");
                var index = $(this).parents("td:first").prevAll().length;
                $tr.find("td:last").html(function () {
                    var sum = parseInt($tr.find("td:eq(1)").html(), 10);
                    return sum - parseInt($tr.find(":text[name='mjje']").val(), 10) - parseInt($tr.find(":text[name='hjje']").val(), 10) + ".00";
                });
                $table.find("tr:last th:eq(" + index + ")").html(function () {
                    var sum = 0;
                    $table.find("tr:gt(1):has(:text)").each(function () {
                        sum += parseInt($(this).find("td:eq(" + index + ") :text").val(), 10);
                    });
                    return sum + ".00";
                });
                $table.find("tr:last th:last").html(function () {
                    var sum = 0;
                    $table.find("tr:gt(1):not(:last)").each(function () {
                        sum += parseInt($(this).find("td:last").html(), 10);
                    });
                    return sum + ".00";
                });
                var orderno = $table.attr("wid");
                $(".jfqk" + orderno + " .jfqkContent:gt(0)").html(function () {
                    var index = $(this).parents("li:first").prevAll().length;
                    if (index == 1) {
                        return $table.find("tr:last th:last").html();
                    }
                    if (index == 2) {
                        return $table.find("tr:last th:eq(2)").html();
                    }
                    if (index == 3) {
                        return $table.find("tr:last th:eq(3)").html();
                    }
                });
                $(".jfqk0 .jfqkContent:gt(0)").html(function () {
                    var index = $(this).parents("li:first").prevAll().length;
                    if (index == 1) {
                        return parseInt($table.find("tr:last th:last").html(), 10) + parseInt($table.siblings("table").find("tr:last th:last").html(), 10) + ".00";
                    }
                    if (index == 2) {
                        return parseInt($table.find("tr:last th:eq(2)").html(), 10) + parseInt($table.siblings("table").find("tr:last th:eq(2)").html(), 10) + ".00";
                    }
                    if (index == 3) {
                        return parseInt($table.find("tr:last th:eq(3)").html(), 10) + parseInt($table.siblings("table").find("tr:last th:eq(3)").html(), 10) + ".00";
                    }
                });
            }).on("keypress", ":text", function () {
                NumberText(event);
            });
            $(document).on("keydown", ":text", function () {
                var mykeyCode;
                if (document.all) {
                    mykeyCode = window.event.keyCode;
                } else {
                    mykeyCode = event.which;
                }
                if (mykeyCode == 13) {
                    $(this).blur();
                }
            });
        });

        function doSearch(id) {
            var val = $("#" + id).val();
            if (val == null || val == "") {
                return false;
            }
            $.get("${basePath}/s/yxqh/gu", {type: id, value: val}, function (data) {
                if (data == null || data == "") {
                    layer.alert("未查询到学生信息，请核实证件号后重新输入！");
                    return false;
                }
                var item = $.parseJSON(data);
                $("#studentinfo ul").empty();
                for (var key in item) {
                    var v = item[key];
                    if(v == null || v=='null'){
                        v = "";
                    }
                    $("#studentinfo ul").append("<li title='" + v + "'>" + key + "：" + v + "</li>");
                }
                $("#userinfo").empty().html('<img id="usertx" src="http://111.12.128.216:8080/UserFiles/Photo/' + item['考生号'] + '.JPG" onload="http://111.12.128.216:8080/UserFiles/Photo/' + item['考生号'] + '.JPG"/>');

                $("#sfzhvalue").val(item['身份证号']);
                $.get("${basePath}/s/yxqh/gs", {sfzh: item['身份证号']}, function (sflbs) {
                    $("#sfxm,#jfqk").empty();
                    $.each($.parseJSON(sflbs), function (j, sflb) {
                        if (sflb.jfqk) {
                            $("#jfqk").append(function () {
                                var html = '<div class="jfqk jfqk' + sflb.orderno + '"><div class="subdivtitle">' + sflb.type + '缴费情况</div><ul>';
                                $.each(sflb.sfXmList, function (k, sfxm) {
                                    html += '<li><div class="jfqkTitle">' + jfnameArray[0] + '（元）</div><div class="jfqkContent">' + sfxm.ysje + '.00</div></li>';
                                    html += '<li><div class="jfqkTitle">' + jfnameArray[1] + '（元）</div><div class="jfqkContent">' + sfxm.sjje + '.00</div></li>';
                                    html += '<li><div class="jfqkTitle">' + jfnameArray[2] + '（元）</div><div class="jfqkContent">' + sfxm.hjje + '.00</div></li>';
                                    html += '<li><div class="jfqkTitle">' + jfnameArray[3] + '（元）</div><div class="jfqkContent">' + sfxm.mjje + '.00</div></li>';
                                });
                                return html + '</ul></div>';
                            });
                        } else {
                            $("#sfxm").append(function () {
                                var html = "<table wid='" + sflb.orderno + "'><tr class='contentTitle'><th colspan='5'>" + sflb.type + "收费</th></tr>";
                                html += "<tr class='thtitle'><th width='50%'>项目</th><th width='50%'>" + jfnameArray[0] + "</th>"
                                + "<th width='50%' class='disth'>" + jfnameArray[2] + "</th><th width='50%' class='disth'>" + jfnameArray[3]
                                + "</th><th width='50%' class='disth'>" + jfnameArray[1] + "</th></tr>";
                                $.each(sflb.sfXmList, function (k, sfxm) {
                                    html += "<tr wid='" + sfxm.id + "'><td>" + sfxm.sfxm + "</td><td>" + sfxm.ysje + ".00</td>"
                                    + "<td class='disth'><input type='text' value='" + sfxm.hjje + ".00' name='hjje'/></td>"
                                    + "<td class='disth'><input type='text' value='" + sfxm.mjje + ".00' name='mjje'/></td><td class='disth'>" + sfxm.sjje + ".00</td></tr>";
                                });
                                html += "<tr class='hjje'><th class='xm'>合计</th><th class='je'>" + sflb.hjysje + ".00</th><th class='disth'>" + sflb.hjhjje
                                + ".00</th><th class='disth'>" + sflb.hjmjje + ".00</th><th class='disth'>" + sflb.hjsjje + ".00</th></tr></table>";
                                return html;
                            });
                        }
                        $("#czan").show();
                        if ($("#jfqkvalue").val() == '1') {
                            $(".greenchannel").hide();
                        } else if ($("#jfqkvalue").val() == '0') {

                        } else if ($("#jfqkvalue").val() == '2') {
                            doGreenchannel();
                            doGreenchannel();
                        }
                        doChangeJfqk($("#jfqkvalue").val());
                    });
                });
            });
        }

        /**
         * 点击绿色通道/取消办理按钮事件
         */
        function doGreenchannel() {
            if ($(".greenchannel").is(":contains('绿色通道')")) {
                $(".thtitle,.disth").show();
                $(".thtitle th").css("width", "20%");
                $(".greenchannel").html("取消办理");
                doChangeJfqk(0);
                $("#sfxm tr:has(:text)").each(function () {
                    $(this).find(":text:first").blur();
                });
            } else {
                $(".thtitle,.disth").hide();
                $(".thtitle th").css("width", "50%");
                $(".greenchannel").html("绿色通道");
                doChangeJfqk(2);
            }
        }

        /**
         * 切换缴费情况
         * 0为合计 1为财务 2为学工
         */
        function doChangeJfqk(type) {
            $("#jfqkvalue").val(type);
            $(".jfqk:not(.jfqk" + type + ")").hide();
            $(".jfqk" + type).show();
        }

        /**
         * 点击提交按钮事件
         */
        function doSubmit() {
            var type = $("#jfqkvalue").val();
            var list = new Array();
            if (type == 0) {
                $("#sfxm table tr:has(td)").each(function () {
                    var sfxm = new Object();
                    sfxm.id = $(this).attr("wid");
                    sfxm.mjje = $(this).find(":text[name='mjje']").val();
                    sfxm.hjje = $(this).find(":text[name='hjje']").val();
                    list.push(sfxm);
                });
            }
            $.post("${basePath}/s/yxqh/s", {
                type: $("#jfqkvalue").val(),
                sfzh: $("#sfzhvalue").val(),
                liststr: JSON.stringify(list)
            }, function () {
                layer.alert("办理成功！", {
                    skin: 'layui-layer-molv' //样式类名
                },function(){
                    if (type == 0) {
                        doGreenchannel();
                    } else {
                        if ($(".jfqk:visible .subdivtitle").find("font").length == 0) {
                            $(".jfqk:visible .subdivtitle").append("<font color='red' style='font-size: 14px;font-family: STKaiti'>（已缴费）</font>");
                        }
                    }
                    $(".layui-layer-close").click();
                });
            });
        }
    </script>
</head>
<body>
<input type="hidden" name="jfqkvalue" id="jfqkvalue" value="${jfqk}"/>
<input type="hidden" name="sfzhvalue" id="sfzhvalue"/>

<div id="main">
    <div id="top">
        <div id="topright"></div>
        <div id="topImg"></div>
        <div id="title">
            <div id="titleSub">
                <div id="logo"></div>
                <div id="titleDiv">
                    <ul>
                        <li>报道办理</li>
                    </ul>
                    <div class="searchDiv">身份证号：<input type="text" name="sfzh" id="sfzh"/></div>
                    <div class="searchDiv">&nbsp;&nbsp;&nbsp;考生号：<input type="text" name="ksh" id="ksh"/></div>
                </div>
            </div>
        </div>
    </div>
    <div id="info">
        <div id="infoSub">
            <div id="userinfo">
            </div>
            <div id="studentinfo">
                <ul>

                </ul>
            </div>
        </div>
    </div>
    <div id="content">
        <div id="contentSub">
            <div id="sfxm">
            </div>
            <div id="jfqk">
            </div>
            <div id="czan">
                <span class="submit">完成提交</span>
                <span class="greenchannel">绿色通道</span>
            </div>
        </div>
    </div>
    <div id="foot">
        版本所有 青海警官职业学院
        <br/>
        学院地址：青海省西宁市城中区建新巷22号 邮 编：810000 电话：0971-8275189 E-mail：chl@qhjymail.com
    </div>
</div>
</body>
</html>
